package Eyjafjalla.monster;

import Eyjafjalla.action.IncreaseInfoAction;
import Eyjafjalla.action.LongWaitAction;
import Eyjafjalla.action.SummonTQBAction;
import Eyjafjalla.card.status.Burn_Eyjafjalla;
import Eyjafjalla.power.GiveRedCloudPower;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.*;
import com.megacrit.cardcrawl.actions.unique.ApplyStasisAction;
import com.megacrit.cardcrawl.actions.utility.WaitAction;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.MonsterStrings;
import com.megacrit.cardcrawl.powers.StrengthPower;

public class DGDGZ extends AbstractEyjafjallaMonster{
    public static final String ID = "eyjafjalla:DGDGZ";
    private static final String MID_PATH = "DGDGZ/enemy_1349_rckshp_2";
    private static final MonsterStrings monsterStrings;
    private static final EnemyType TYPE = EnemyType.ELITE;
    private static final String ATTACK_NAME = "Attack_B";
    private static final String SKILL_NAME = "Attack_A";
    private static final String IDLE_NAME = "Idle";
    private static final String DIE_NAME = "Die";

    public LTTQB[] lttqbs = new LTTQB[3];
    public static float[] xPad = new float[]{
      -270F,
      -520F,
      -770F
    };
    public static float[] yPad = new float[]{
      -10F,
      0F,
      10F
    };

    public boolean full(){
        boolean full = true;
        for(int i =0;i<lttqbs.length;i++){
            if(lttqbs[i]==null){
                full = false;
            }
            else if(lttqbs[i].isDeadOrEscaped()){
                full = false;
                lttqbs[i] = null;
            }
        }
        return full;
    }

    int summonRemains = 1;

    int attack;
    int increase;
    float waitTime = 0.45F;
    float skillTime = 0.8F;
    int lastRecordHealth;

    public void setFastMode(){
        state.setTimeScale(1);
        this.waitTime = 0.45F;
    }

    public DGDGZ(float x,float y){
        super(monsterStrings.NAME,ID,TYPE,96,240F,230F,x,y);
        setSpine(MID_PATH,1.6F);
        setFastMode();
        this.state.setAnimation(0,IDLE_NAME,true);
        this.summonRemains = 1;
        if(AbstractDungeon.ascensionLevel>=8){
            setHp(450);
        }
        else {
            setHp(400);
        }
        if(AbstractDungeon.ascensionLevel>=3){
            attack = 30;
        }
        else {
            attack = 27;
        }
        if(AbstractDungeon.ascensionLevel>=18){
            increase = 10;
        }
        else {
            increase = 9;
        }
        lastRecordHealth = this.currentHealth;
        this.damage.add(new DamageInfo(this,this.attack, DamageInfo.DamageType.NORMAL));
    }

    @Override
    public void usePreBattleAction() {
        addToBot(new ApplyPowerAction(this,this,new GiveRedCloudPower(this,1),1));
        super.usePreBattleAction();
    }

    @Override
    protected void getMove(int i) {
        if(summonRemains<=0||full()){
            this.setMove((byte) 1,Intent.ATTACK,this.damage.get(0).base);
        }
        else {
            this.setMove((byte) 2,Intent.UNKNOWN);
        }
    }

    @Override
    public void takeTurn() {
        setFastMode();
        switch (this.nextMove){
            case 1:{
                addToBot(new ChangeStateAction(this,"ATTACK"));
                addToBot(new LongWaitAction(this.waitTime));
                addToBot(new DamageAction(AbstractDungeon.player,this.damage.get(0), AbstractGameAction.AttackEffect.BLUNT_HEAVY));
                addToBot(new IncreaseInfoAction(damage.get(0),increase));
                break;
            }
            case 2:{
                summonRemains--;
                addToBot(new ChangeStateAction(this,"SKILL"));
                addToBot(new LongWaitAction(this.skillTime));
                addToBot(new SummonTQBAction(this));
                break;
            }
        }

        addToBot(new RollMoveAction(this));
    }

    @Override
    public void changeState(String stateName) {
        switch (stateName){
            case "ATTACK":{
                this.state.setAnimation(0,ATTACK_NAME,false);
                this.state.addAnimation(0,IDLE_NAME,true,0F);
                break;
            }
            case "SKILL":{
                this.state.setAnimation(0,SKILL_NAME,false);
                this.state.addAnimation(0,IDLE_NAME,true,0F);
                break;
            }
            default:
                break;
        }
    }

    @Override
    public void damage(DamageInfo info) {
        super.damage(info);
        while (lastRecordHealth-currentHealth >= 100){
            lastRecordHealth-=100;
            summonRemains++;
        }
    }

    @Override
    public void die() {
        this.state.setTimeScale(1F);
        state.setAnimation(0,DIE_NAME,false);
        super.die();

    }

    static {
        monsterStrings = CardCrawlGame.languagePack.getMonsterStrings(ID);
    }
}

